package com.stylefeng.guns.core.execl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.stylefeng.guns.common.persistence.dto.ExportOrder;
import com.stylefeng.guns.common.persistence.model.InitialOrder;
import com.stylefeng.guns.core.util.JsonUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.BeanUtils;


/**
 * Created by chunmeng.lu
 * Date: 2016-20-04 10:42
 */
public class ExcelTest {

	public static void main(String[] args) throws Exception {
		testCreateExcel();
		//testParse();
	}

	public static void testCreateExcel() throws Exception {
		EasyExcel fastExcel = new EasyExcel("d://data.xls");
		List<ExportOrder> list = new ArrayList<ExportOrder>();
		for (int i = 0; i < 10; i++) {
			ExportOrder test = new ExportOrder();
			test.setGoodsName("1111111");
			list.add(test);
		}
		fastExcel.createExcel(list);
		fastExcel.close();
	}

	public static void testParse() throws Exception {
		EasyExcel fastExcel = new EasyExcel("D:\\document\\workfiles\\outsource\\ldp\\导入模板\\template1.xlsx");
		fastExcel.setSheetName("Sheet1");
		List<ExportOrder> exportOrders = fastExcel.parse(ExportOrder.class);

		List<InitialOrder> initOrders = new ArrayList<InitialOrder>();
		for(ExportOrder export:exportOrders){
			InitialOrder initialOrder=new InitialOrder();
			BeanUtils.copyProperties(export,initialOrder);
			initOrders.add(initialOrder);
		}
		if(null != exportOrders && !exportOrders.isEmpty()) {
			for(ExportOrder exportOrder : exportOrders) {
				System.out.println(JsonUtils.toJson(exportOrder));
			}
		} else {
			System.out.println("没有结果");
		}
		fastExcel.close();
	}
}
